﻿using System.IO;
using System.Linq;

namespace Mitosoft.Definitions.Calculations
{
  public class Calculations
  {
    /// <summary>
    /// Gets the last part of the given full path.
    /// Example: fullPath = "C:\MyDir\MySubDir" returns "MySubDir"
    /// </summary>
    /// <param name="fullPath">Represents the full path.</param>
    /// <returns>Returns the last part of the given full path.</returns>
    public static string GetLastPartOfFullPath(string fullPath)
    {
      if (string.IsNullOrEmpty(fullPath))
        return fullPath; // return String.Empty or null

      return
        (fullPath.Last() == Path.DirectorySeparatorChar ? 
          fullPath.Remove(fullPath.Length - 1) : fullPath).
            Split(Path.DirectorySeparatorChar).Last();
    }
  }
}
